package com.xt.helloword;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;


enum Type {
    头等舱, 经济舱
}

public class Demo1 {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        double price = BuyAirTickets(1000, 8, Type.经济舱);
//        System.out.println("优惠后价格为:" + price);

//        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
//        System.out.println(CheckCode(n));
//        System.out.println(Score(5));
//        System.out.println(digitalEncryption("1983"));
//        lottery();
//        System.out.println(FindPrimeNumbers(0, 100));
//        multiplicationTable();
//        userSelectNumber();
//        toString1(winningNumber());
        isWinning(userSelectNumber(),winningNumber());
    }

    /**
     * 买飞机票
     *
     * @param price 价格
     * @param month 月份
     * @param type  类型
     */
    static double BuyAirTickets(double price, int month, Type type) {
        if (month >= 5 && month <= 10) {
            switch (type) {
                case Type.头等舱:
                    price *= 0.9;
                    break;
                case Type.经济舱:
                    price *= 0.85;
                    break;
            }
            System.out.println(price);
            System.out.println(month);
            System.out.println(type);
            System.out.println("旺季");
        } else {
            switch (type) {
                case Type.头等舱:
                    price *= 0.7;
                    break;
                case Type.经济舱:
                    price *= 0.65;
                    break;
            }
            System.out.println(price);
            System.out.println(month);
            System.out.println(type);
            System.out.println("淡季");
        }
        return price;
    }

    /**
     * 生成验证码
     *
     * @param n 需要多少位验证码
     * @return
     */
    static String CheckCode(int n) {
        Random r = new Random();
        StringBuilder code = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int type = r.nextInt(3); // 0代表数字, 1代表小写字母, 代表大写字母
            switch (type) {
                case 0:
                    code.append(r.nextInt(10));
                    break;
                case 1:
                    char str1 = (char) (r.nextInt(26) + 65);
                    code.append(String.valueOf(str1));
                    break;
                case 2:
                    char str2 = (char) (r.nextInt(26) + 97);
                    code.append(String.valueOf(str2));
                    break;
            }
        }
        return code.toString();
    }

    /**
     * 打分
     *
     * @param n
     * @return
     */
    static double Score(int n) {
        int[] score = new int[n];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < n; i++) {
            System.out.println("请你录入第" + (i + 1) + "个评委的分数");
            score[i] = sc.nextInt();
        }
        int sum = 0;
        int max = score[0];
        int min = score[0];
        for (int i = 1; i < score.length; i++) {
            if (score[i] > max) {
                max = score[i];
            }
            if (score[i] < min) {
                min = score[i];
            }
            sum += score[i];
        }
        double svg = 1.0 * (sum - max - min) / (n - 2);
        System.out.println("最终得分是: " + svg);
        return svg;
    }

    static String digitalEncryption(String password) {
        int[] number = split(password);

        for (int i = 0; i < number.length; i++) {
            number[i] = (number[i] + 5) % 10;
        }
        reverse(number);

        String data = "";
        for (int i = 0; i < number.length; i++) {
            data = data + number[i];
        }

        return data;
    }

    public static int[] split(String str) {
//        String[] arr = str.split(" ");
//        int len = arr.length;
//        int[] number = new int[len];
//        for (int i = 0; i < len; i++) {
//            number[i] = Integer.parseInt(arr[i]);
//        }
//        return number;
        int[] number = new int[str.length()];
        for (int i = 0; i < str.length(); i++) {
            number[i] = str.charAt(i) - '0';
        }
        return number;
    }

    public static void reverse(int[] arr) {
        for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        System.out.println(Arrays.toString(arr));
    }

    public static int[] copy(int[] arr) {
        int[] newArr = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }

    public static void lottery() {
        Scanner sc = new Scanner(System.in);
        Random rd = new Random();
        int[] money = {9, 666, 188, 520, 99999};
        for (int i = 0; i < 5; i++) {
            System.out.println("请按任意键完成抽奖");
            sc.next(); // 等待用户按了回车才往下走
            int rdValue = rd.nextInt(money.length);
            int moneyOne = money[rdValue];
            if (moneyOne != 0) {
                System.out.println("恭喜您抽中: " + moneyOne);
                money[rdValue] = 0;
            } else {
                System.out.println("很遗憾未抽中");
            }
        }
        System.out.println("活动结束");
    }

    public static int FindPrimeNumbers(int start, int end) {
        int num = 0;
        for (int i = start; i < end; i++) {
            if (i == 1) {
                continue;
            }
            if (!(i % 2 == 0 || i % 3 == 0 || i % 5 == 0)) {
                num += 1;
                System.out.println(i);
            }
        }
        return num;
    }

    //    打印久久乘法表
    public static void multiplicationTable() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
//                System.out.print(ddStr(j) + "X" + ddStr(i) + "=" + ddStr(i * j) + ' ');
                System.out.print(j + "x" + i + "=" + i * j + "\t");
            }
            System.out.println("");
        }
    }

    //    小于10补0
    public static String ddStr(int number) {
        if (number < 10 && number > 0) {
            return "0" + number;
        }
        return "" + number;
    }

    // 双色球系统的开发
    public static int[] userSelectNumber() {
        int[] number = new int[7];
        for (int i = 0; i < number.length - 1; i++) {
            while (true) {
                System.out.println("请您输入第" + (i + 1) + "红球号码");
                Scanner sc = new Scanner(System.in);
                int num = sc.nextInt();
                if (num < 1 || num > 33) {
                    System.out.println("对不起! 您输入的红球号码不在1~33之间, 请重新选择");
                } else if (exist(num, number)) {
                    System.out.println("对不起! 您输入的红球号码重复了, 请重新选择");
                } else {
                    number[i] = num;
                    break;
                }
            }

        }

        while (true) {
            System.out.println("请您输入第" + number.length + "篮球号码");
            Scanner sc = new Scanner(System.in);
            int num = sc.nextInt();
            if (num < 1 || num > 16) {
                System.out.println("对不起! 您输入的篮球号码不在1-16之间, 请重新选择");
            } else {
                number[number.length - 1] = num;
                break;
            }
        }
        return number;
    }

    // 生成双色球中奖号码
    public static int[] winningNumber() {
        int[] number = new int[7];
        Random random = new Random();
        for (int i = 0; i < number.length - 1; i++) {
            while (true) {
                int num = random.nextInt(33) + 1;
                if (!exist(num, number)) {
                    number[i] = num;
                    break;
                }
            }
        }
        int num = random.nextInt(16) + 1;
        number[number.length - 1] = num;
        return number;
    }

    // 判断双色器是否中奖
    public static boolean isWinning(int[] number1, int[] number2) {
        if (number1.length != number2.length) return false;
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < number1.length - 1; i++) {
            if (number1[i] == number2[i]) redCount++;
        }
        if (number1[6] == number2[6]) {
            blueCount++;
        }
        System.out.println(Arrays.toString(number1));
        System.out.println(Arrays.toString(number2));
        System.out.println("红球中奖个数"+redCount);
        System.out.println("篮球中奖个数"+blueCount);
        if(redCount == 6 &&  blueCount == 1) {
            System.out.println("恭喜您, 中奖1000万, 可以开始享受人生了~~~");
            return true;
        }else if(redCount == 6 && blueCount == 0) {
            System.out.println("恭喜您, 中奖500万, 可以稍微开始享受人生了~~~");
            return true;
        }else if(redCount == 5 && blueCount == 1) {
            System.out.println("恭喜您, 中奖3000元, 可以出去吃顿小龙虾");
            return true;
        }else if(redCount == 5 && blueCount == 0 || redCount == 4 && blueCount == 1) {
            System.out.println("恭喜您, 中奖200元");
            return true;
        }else if(redCount == 3 && blueCount == 1 || redCount == 2 && blueCount == 1 ) {
            System.out.println("恭喜您 , 中奖10元");
            return true;
        }else if(redCount == 1 && blueCount == 1 || redCount == 0 && blueCount == 1 ) {
            System.out.println("恭喜您 , 中奖5元");
            return true;
        }else{
            System.out.println("再接再厉");
            return false;
        }

    }

    //    判断元素是否在数组中
    public static Boolean exist(int number, int[] numberArr) {
        for (int i = 0; i < numberArr.length; i++) {
            if (numberArr[i] == number) {
                return true;
            }
        }
        return false;
    }

    // toString
    public static void toString1(int[] num) {
        System.out.print("[");
        for (int i = 0; i < num.length; i++) {
            System.out.print(num[i] + (num.length - 1 == i ? "" : ","));
        }
        System.out.print("]");
    }


}


